﻿using JESAI.Application.Abstractions.Uniform;
using JESAI.Core.Attributes;
using JESAI.DynamicCodeRun.Providers;
using JESAI.DynamicCodeRun.Run;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JESAI.Application.Service.Uniform
{
    [AppService]
    public class UniformApiService : IUniformApiService
    {
        private readonly IDynamicCodeRunProvider _dynamicCodeRunProvider;

        public UniformApiService(IDynamicCodeRunProvider dynamicCodeRunProvider)
        {
            _dynamicCodeRunProvider = dynamicCodeRunProvider;
        }

        public async Task<string> Execute(string codeidentify, string param)
        {
            var result = await _dynamicCodeRunProvider.RunCode(codeidentify, param);
            if (result.ResultCode == RunResultType.Success)
            {
                return result.Output;
            }
            else
            {
                throw new Exception(result.Error);
            }
        }
    }
}
